package puppy.graph;


import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.regex.Pattern;

import javax.swing.JFrame;

import puppy.query.QueryNGramExtractor;
import util.io.FileInput;

import edu.uci.ics.jung.graph.UndirectedSparseGraph;
import fileloaders.mallet.MalletTopicsProbs;
import fileloaders.parsers.InLineParser;

public class CreateUnigrams {


	
	
	private Pattern tab = Pattern.compile("\t");
	public Hashtable<String, DeliciousNode> nodes = new Hashtable<String, DeliciousNode>();

	AgeAggregator agg= null;


	
	public  Hashtable<String, HashSet<String>> ages =new Hashtable<String,HashSet<String>>();
	public CreateUnigrams(AgeAggregator agg,String path){
		this.agg= agg;
		initGraph(path);
	}
	
	public void initGraph(String path) {

		FileInput in = new FileInput(path);
		
		
		String line = in.readString();
		
		int j =0;
		while (line != null) {
		//	System.out.println("Adding " + line);
			dumpLineIntoGraphDirected(line);
			line = in.readString();
			j++;
	//	if(j==5) return;
		}
	}


	public void aggreageteValueInHash(Hashtable<String,Integer>h, String key, int value){
		
		if(h.containsKey(key)){
			
			h.put(key, h.get(key)+ value);
			
		}else{
			
			h.put(key, value);
			
		}
		
	}
	
	private void dumpLineIntoGraphDirected(	String line) {
		
		String[] fields =  tab.split(line);

		//System.out.println(line);
		line =null;
		 InLineParser.parseGraphEnrichedLine(fields,agg,ages ,nodes);
		
	
	}
	
	
	

}
